package com.monkeygroup.mygoplus.view.home.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.common.utils.LocalInfo;
import com.monkeygroup.mygoplus.common.utils.StringUtil;
import com.monkeygroup.mygoplus.thing.vo.ZoneVO;
import com.monkeygroup.mygoplus.view.home.activity.sell.PublishedActivity;




import java.util.ArrayList;
import java.util.List;


/**
 * 店鋪配置
 * Created by admin on 2017/6/4.
 */

public class PublishedChooseShopEquipActivity extends BaseActivity implements View.OnClickListener{

    public static void gotoActivity(Activity activity,String type,String content) {
        Intent intent = new Intent(activity,
                PublishedChooseShopEquipActivity.class);

        intent.putExtra("type", type);
        intent.putExtra("content", content);

        activity.startActivityForResult(intent,12+Integer.parseInt(type));

    }

    private ImageView imgBack;
    private TextView txt_top,txtTitle;
    private Activity activity;

    private List<String> leftListItems;
    private StringBuffer property_equipment;
    private String type,content;

    @Override
    public void onClick(View view) {

    }

    @Override
    public void setContentView() {
        setContentView(R.layout.published_choose_shopequip);
    }

    @Override
    public void initView() {

          property_equipment=new StringBuffer("");

        Intent intent = this.getIntent();
        Bundle bundle =  intent.getExtras();
        type = bundle.getString("type");
        content = bundle.getString("content");

        activity=PublishedChooseShopEquipActivity.this;
        leftListItems = new ArrayList<String>();

        //提供設備
        if("1".equals(type)){
            leftListItems.add("客梯");
            leftListItems.add("貨梯");
            leftListItems.add("扶梯");
            leftListItems.add("暖氣");
            leftListItems.add("冷氣");
            leftListItems.add("停車位");
            leftListItems.add("水");
            leftListItems.add("天然氣");
            leftListItems.add("網路");
        }
        //土地使用類型
        else  if("2".equals(type)){
            leftListItems.add("甲種建築用地");
            leftListItems.add("乙種建築用地");
            leftListItems.add("丙種建築用地");
            leftListItems.add("丁種建築用地");
            leftListItems.add("農牧用地");
            leftListItems.add("養殖用地");
            leftListItems.add("遊憩用地");
            leftListItems.add("墳墓用地");
            leftListItems.add("鹽業用地");
            leftListItems.add("林業用地");
            leftListItems.add("礦業用地");
            leftListItems.add("窯業用地");
            leftListItems.add("交通用地");
            leftListItems.add("水利用地");
            leftListItems.add("古跡保存用地");
            leftListItems.add("生態保護用地");
            leftListItems.add("國土保安用地");
            leftListItems.add("特定目的事業用地");
            leftListItems.add("其他");
        }
        //土地使用屬性
        else  if("3".equals(type)){
            leftListItems.add("住宅區");
            leftListItems.add("商業區");
            leftListItems.add("工業用地");
            leftListItems.add("文教區");
            leftListItems.add("風景區");
            leftListItems.add("保護區");
            leftListItems.add("行政區");
            leftListItems.add("特定農業區");
            leftListItems.add("一般農業區");
            leftListItems.add("鄉村區");
            leftListItems.add("森林區");
            leftListItems.add("山坡地保育區");
            leftListItems.add("公園區");
            leftListItems.add("河川區");
            leftListItems.add("其他或專用區");
        }

        //租房提供設備
        else if("4".equals(type)){
            leftListItems.add("電視");
            leftListItems.add("冷氣");
            leftListItems.add("冰箱");
            leftListItems.add("熱水器");
            leftListItems.add("洗衣機");
            leftListItems.add("天然瓦斯");
            leftListItems.add("第四台");
            leftListItems.add("網路");
            leftListItems.add("瓦斯爐");
            leftListItems.add("飲水機");
            leftListItems.add("電磁爐");
            leftListItems.add("天然氣");
        }
        //提供家具
        else if("5".equals(type)){
            leftListItems.add("床");
            leftListItems.add("衣櫃");
            leftListItems.add("沙發");
            leftListItems.add("書桌椅");
            leftListItems.add("茶几");
            leftListItems.add("書架");
            leftListItems.add("椅子");
            leftListItems.add("餐桌椅");
        }
        //租金包含
        else if("6".equals(type)){
            leftListItems.add("電費");
            leftListItems.add("第四台");
            leftListItems.add("網路");
            leftListItems.add("瓦斯費");
            leftListItems.add("水費");
        }



        imgBack = (ImageView) findViewById(R.id.img_back);
        txtTitle = (TextView) findViewById(R.id.txt_title);
        txt_top = (TextView) findViewById(R.id.txt_top);
        txt_top.setText("确定");

        txtTitle.setText("提供配置");
        ListView shopEquip = (ListView)findViewById(R.id.publish_shopequip_list);
        LeftAdapter adapter = new LeftAdapter(activity);
        shopEquip.setAdapter(adapter);

    }

    @Override
    public void setListener() {

        imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               finish();
            }
        });

        txt_top.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent intent=new Intent();
                intent.putExtra("property_equipment", String.valueOf(property_equipment));

                PublishedChooseShopEquipActivity.this.setResult(RESULT_OK,intent);
                finish();
            }
        });

    }

    @Override
    public void doEvent() {

    }

    public class LeftAdapter extends BaseAdapter {


        private LayoutInflater mInflater;



        public LeftAdapter(Context context) {
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return leftListItems.size();
        }

        @Override
        public Object getItem(int position) {
            return leftListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View myconvertView, ViewGroup parent) {

            View leftconvertView = mInflater.inflate(R.layout.published_choose_shopequip_item, null);
            final String obj = leftListItems.get(position);
            final TextView txtName = (TextView) leftconvertView
                    .findViewById(R.id.txt_publish_content);
            final CheckBox checkhopequip = (CheckBox) leftconvertView
                    .findViewById(R.id.check_shopequip);

            txtName.setText(obj);
            if(!StringUtil.isBlank(content)){
                String[] choose = content.split(",");
                for(int i=0;i<choose.length;i++){
                    if(position==i){
                        checkhopequip.setChecked(true);
                    }
                }
            }
            checkhopequip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){

                            property_equipment.append(""+(position+1));
                            property_equipment.append(",");
                    }
                    else{
                        property_equipment.toString().replace(position+",","");
                    }
                }
            });


            return leftconvertView;
        }

    }









}
